<template>
  <div class="brand">
    <el-card class="margin-30" shadow="never">
      <div slot="header">
        <span>分类管理</span>
      </div>
      <div class="bold">乐居分类:</div>
      <div class="brand-list">
        <el-card v-for="item in productCategory" :key="item.id" class="brand-list-item" shadow="hover">
          <div slot="header">
            <span>{{ item.name }}</span>
          </div>
          <img :src="item.icon" alt="">
        </el-card>

      </div>
      <div class="bold">全部分类:</div>
      <el-table
        :data="allCategory"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
        :default-expand-all="false"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      >
        <el-table-column
          prop="name"
          label="菜单名称"
          width="180"
        />
        <el-table-column
          label="icon"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <img width="50" height="50" :src="scope.row.icon" alt="">
          </template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="分类名字"
          width="180"
          align="center"
        />
        <el-table-column
          prop="sort"
          label="排序"
          width="100"
          align="center"
        />
        <el-table-column
          prop="sort"
          label="显示状态"
          width="160"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.showStatus?'显示':'不显示' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="sort"
          label="导航栏展示"
          width="160"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.navStatus?'显示':'不显示' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="description"
          label="描述"
          width="180"
          align="center"
        />
        <el-table-column
          prop="createTime"
          label="创建时间"
          width="200"
          align="center"
        />
      </el-table>

    </el-card>

  </div>
</template>

<script>
import {
  getAllCategory as getAllCategoryApi
} from '@/api/product/list'
export default {
  name: 'ProductCategory',
  data() {
    return {
      productCategory: [],
      allCategory: []
    }
  },
  created() {
    this.getBrandList()
  },
  methods: {
    getBrandList() {
      getAllCategoryApi()
        .then(res => {
          const { message, success, data } = res
          if (success) {
            var item = data.items.find(ele => ele.category.name === '乐居')
            this.productCategory = item.children
            this.allCategory = data.items.map(ele => {
              var obj = Object.assign({}, ele.category)
              obj.children = ele.children
              return obj
            })
          } else {
            this.$message.error(message)
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.bold{
  font-weight: 700;
  margin-bottom: 30px;
}
.brand{
  &-list{
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    &-item{
      width: 323px;
      height: 401px;
      margin-bottom: 20px;
      img{
        width: 283px;
        height: 300px;
      }
    }
  }
}
</style>

